package com.wc.AlgoOJ_train.train1.c8.A804;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/11 21:11
 * @description 找单词
 * http://43.138.190.70:8888/p/A804
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while (n-- > 0) {
            int[] leNum = new int[26 + 1];
            for (int i = 1; i <= 26; i++) {
                leNum[i] = sc.nextInt();
            }

            int[][] dp = new int[26 + 1][50 + 1];
            dp[0][0] = 1;
            for (int i = 1; i <= 26; i++) {
                for (int j = 0; j <= 50; j++) {
                    int num = 0;
                    while (j >= num * i && num <= leNum[i]) {
                        dp[i][j] += dp[i - 1][j - num * i];
                        num++;
                    }
                }
            }
            long ans = 0;
            for (int i = 1; i <= 50; i++) {
                ans += dp[26][i];
            }
            out.println(ans);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }
}



